﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KeaoBase;

namespace DataCenter.Models.WeiXin
{
    public class BaseWeiXinMsg
    {
        public BaseWeiXinMsg(KeaoXmlHelper XmlHelper)
        {
            this.FromUserName = XmlHelper.GetFirstNodeInnerString("FromUserName");
            this.ToUserName = XmlHelper.GetFirstNodeInnerString("ToUserName");
            this.CreateTime = XmlHelper.GetFirstNodeInnerValue<long>("CreateTime");
            this.MsgType = XmlHelper.GetFirstNodeInnerString("MsgType");
        }

        public string ToUserName { get; set; }
        public string FromUserName { get; set; }
        public long? CreateTime { get; set; }
        public string MsgType { get; set; }

        public string ReturnTextMsg(string MsgContent)
        {
            if (!string.IsNullOrEmpty(MsgContent))
            {
                string returnMsg = @"<xml>
                                <ToUserName><![CDATA[{0}]]></ToUserName>
                                <FromUserName><![CDATA[{1}]]></FromUserName>
                                <CreateTime>{2}</CreateTime>
                                <MsgType><![CDATA[text]]></MsgType>
                                <Content><![CDATA[{3}]]></Content>
                                </xml>";
                returnMsg = string.Format(returnMsg, FromUserName, ToUserName, KeaoBase.KeaoUtils.Datetime2Timestamp(DateTime.Now), MsgContent);
                return returnMsg;
            }
            else
            {
                return "success";
            }
        }

        /// <summary>
        /// 响应
        /// </summary>
        public virtual string ResponseResult()
        {
           return ReturnTextMsg("");
        }

    }
}